package com.kevin.common.util;

import cn.hutool.extra.servlet.ServletUtil;

import javax.servlet.http.HttpServletRequest;

/**
 * ip工具类 解决hutool ip获取问题
 *
 * @author wh
 * @date 2023/4/6 10:56
 */
public class IpUtil {

    /**
     * 获取客户端ip
     *
     * @param request          请求
     * @param otherHeaderNames 其他标题名称
     * @return {@code String}
     */
    public static String getClientIP(HttpServletRequest request, String... otherHeaderNames) {
        String ip = ServletUtil.getClientIP(request, otherHeaderNames);
        if ("0:0:0:0:0:0:0:1".equals(ip)) {
            ip = "127.0.0.1";
        }
        return ip;
    }
}
